package com.wmc;

import java.util.HashMap;
import java.util.Random;

import com.databasefunction.AllDBFunction;
import com.databasefunction.DatabaseConstants;
import com.menu.Constants;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class WMCTareweightSubmit extends ActionSupport{
	String rstnumber;
	HashMap hashMap;
	public String getRstnumber() {
		return rstnumber;
	}

	public void setRstnumber(String rstnumber) {
		this.rstnumber = rstnumber;
	}
	 

@Override
public String execute() throws Exception {
	System.out.println("In WMCAction");
	String userrole = (String) ActionContext.getContext().getSession().get("userrole"); 
	if ((null != userrole) && (userrole.equals("weightmachine") || userrole.equals("admin") || userrole.equals("superadmin"))) {
		ActionContext.getContext().getSession().put("rstdatamap", hashMap);
		return "success";
	}else
		return Constants.UNAUTHORISED;
	}

@Override
public void validate() {
	// TODO Auto-generated method stub
	AllDBFunction allDBFunction = new AllDBFunction();
	hashMap = allDBFunction.getRSTData(rstnumber);
	if (hashMap == null) {
		addActionError("Rst number not found");
	}else{
		String rstisavail = (String) hashMap.get("netWeight");
		if (null!=rstisavail && !rstisavail.equals("")) {
			addActionError("Rst number is not availbale to edit");
		}
	}
}

	
}
